import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store/index'
import VueClipboard from 'vue-clipboard2';
import directives from './assets/js/directives'
import Loading from './components/modal/loading';
import Success from './components/modal/success';
import Alert_shot from './components/modal/alert_shot';
import Alert_little from './components/modal/alert_little';
import Prompt from './components/modal/prompt';
import Sicbo_explain from './components/modal/sicbo_explain';
import Efomo_tip from './components/modal/efomo_tip';
import Efomo_list from './components/modal/efomo_list';
import Efomo_table from './components/modal/efomo_table';


// import fastClick from 'fastclick'

// fastClick.attach(document.body);			//手机环境点击0.2秒延迟强制取消

import {mapActions, mapState} from 'vuex'

import VueTouch from 'vue-touch'

Vue.use(VueTouch, {name: 'v-touch'});
directives.init(Vue);
// mint-ui
import {Range, InfiniteScroll} from 'mint-ui';

Vue.component(Range.name, Range);
import 'mint-ui/lib/style.css'

// 多语言插件
import VueI18n from 'vue-i18n'

Vue.use(VueI18n);
const i18n = new VueI18n({
    locale: localStorage.getItem("lang") ? localStorage.getItem("lang") : 'en-US',
    messages: {
        'zh-CN': require('./assets/js/language/cn/index'),   // 中文语言包
        'en-US': require('./assets/js/language/en/index')    // 英文语言包
    }
});
Vue.component('Loading', Loading);
Vue.component('Success', Success);
Vue.component('Alert_shot', Alert_shot);
Vue.component('Alert_little', Alert_little);
Vue.component('Prompt', Prompt);
Vue.component('Sicbo_explain', Sicbo_explain);
Vue.component('Efomo_tip', Efomo_tip);
Vue.component('Efomo_list', Efomo_list);
Vue.component('Efomo_table', Efomo_table);


Vue.component(Range.name, Range);

Vue.use(InfiniteScroll);
Vue.use(VueClipboard);

Vue.config.productionTip = false;
import {requestConfig} from "./assets/js/config/host";

Vue.prototype.requestConfig = requestConfig;

Vue.mixin({
    /* eslint-disable */
    filters: {
        //舍入过滤器
        roundOff(num, digit) {
            num = parseFloat(num);
            return (Math.floor(num * Math.pow(10, digit)) / Math.pow(10, digit)).toFixed(digit);
        },

        time2Date: function (timestamp) {
            let time = new Date(timestamp * 1000);
            let y = time.getFullYear();
            let m = time.getMonth() + 1;
            let d = time.getDate();
            let h = time.getHours();
            let mm = time.getMinutes();
            let s = time.getSeconds();
            return y + '-' + m + '-' + d + ' ' + h + ':' + mm + ':' + s;
        },
        time2DateFomo: function (timestamp) { //无年 秒
            let time = new Date(timestamp * 1000);
            let m = time.getMonth() + 1;
            let d = time.getDate();
            let h = time.getHours();
            let mm = time.getMinutes();
            return m + '-' + d + ' ' + h + ':' + mm;
        }, time2DateLottery: function (timestamp) { //分年月日 无秒
            let time = new Date(timestamp * 1000);
            let y = time.getFullYear();
            let m = time.getMonth() + 1;
            let d = time.getDate();
            let h = time.getHours();
            let mm = time.getMinutes();
            let s = time.getSeconds();
            return y + '-' + m + '-' + d + ' ' + h + ':' + mm;
        },

    },
    computed: {
        ...mapState([
            "routePath", "balance", "currency", "exchange", "backUrl", "transitionName"
        ]),
        ...mapState("wallet", [
            "walletActive", "walletCreate", "walletDecode"
        ]),
        ...mapState("modal", [
            "alert_shot", "loading", "success", "alert_little", "prompt"
        ]),
        ...mapState("sicbo", [
            "round", "cpt"
        ]),
        ...mapState("fomo", [
            "fomoInfo", "fomotip", "lottery_list", "WeekWinnerList", "LastWinnerList"
        ])
    },
    methods: {
        changeRoute(newRoute, routeQuery = {}) {
            router.push({path: newRoute, query: routeQuery});
        },
        backRoute() {
            router.go(-1);
        },
        // 禁用浏览器滚动
        scrollFunc(evt) {
            evt = evt || window.event;
            if (evt.preventDefault) {
                // Firefox
                evt.preventDefault();
                evt.stopPropagation();
            } else {
                // IE
                evt.cancelBubble = true;
                evt.returnValue = false;
            }
            return false;
        },
        plusDiff: function (callBack) {
            if (typeof plus != "undefined") {
                callBack();
            }
        },
        addressSub: function (address = '', length = 10) {
            return address.substring(0, length) + "..." + address.substring(address.length - length, address.length);
        },
        openWebview: function (url) {
            if (typeof plus != 'undefined') {
                plus.webview.open(url);
            } else {
                window.open(url);
            }
        },
        isImmersed: function () {
            if (typeof plus != "undefined") {
                return plus.navigator.isImmersedStatusbar();
            } else {
                return false;
            }
        },
        ...mapActions([
            'aRoutePathPush',
            'aRoutePathDel',
            'aTransitionName'
        ]),
        ...mapActions('wallet', [
            'aWalletCreate',
            'aWalletActive',
            "aWalletDecode"
        ]),
        ...mapActions('modal', [
            'aLoading',
            'aSuccess',
            'aAlert_shot',
            'aAlert_little',
            'aPrompt'
        ]),
        ...mapActions('sicbo', [
            'aCpt',
        ]),
        ...mapActions('fomo', [
            'aShowTip', 'aShowList', 'aWeekWinnerList', 'aLastWinnerList', "aFomoInfo"
        ]),

    }
});

new Vue({
    router,
    store,
    i18n,
    render: h => h(App),
}).$mount('#app');
